import board
import digitalio
import time

DA0 = digitalio.DigitalInOut(board.GP28)
DA1 = digitalio.DigitalInOut(board.GP29)
DA2 = digitalio.DigitalInOut(board.GP30)
DA3 = digitalio.DigitalInOut(board.GP31)
DA4 = digitalio.DigitalInOut(board.GP32)
DA5 = digitalio.DigitalInOut(board.GP33)
DA6 = digitalio.DigitalInOut(board.GP34)
DA7 = digitalio.DigitalInOut(board.GP35)
DA8 = digitalio.DigitalInOut(board.GP36)
DA9 = digitalio.DigitalInOut(board.GP37)

DA0.direction = digitalio.Direction.OUTPUT
DA1.direction = digitalio.Direction.OUTPUT
DA2.direction = digitalio.Direction.OUTPUT
DA3.direction = digitalio.Direction.OUTPUT
DA4.direction = digitalio.Direction.OUTPUT
DA5.direction = digitalio.Direction.OUTPUT
DA6.direction = digitalio.Direction.OUTPUT
DA7.direction = digitalio.Direction.OUTPUT
DA8.direction = digitalio.Direction.OUTPUT
DA9.direction = digitalio.Direction.OUTPUT

# data = [511, 669, 811, 924, 997, 1022, 997, 924, 811, 669, 511, 353, 211, 98, 25, 0, 25, 98, 211, 353]

def get_DAC_data(cmd):
    
    # SINE
    if(cmd == "0"):
        data = [511, 543, 575, 607, 638, 669, 699, 729, 757, 785, 811, 837, 861, 884, 905, 924, 942, 959, 973, 986, 997, 1006, 1013, 1018, 1021, 1022, 1021, 1018, 1013, 1006, 997, 986, 973, 959, 942, 924, 905, 884, 861, 837, 811, 785, 757, 729, 699, 669, 638, 607, 575, 543, 511, 479, 447, 415, 384, 353, 323, 293, 265, 237, 211, 185, 161, 138, 117, 98, 80, 63, 49, 36, 25, 16, 9, 4, 1, 0, 1, 4, 9, 16, 25, 36, 49, 63, 80, 98, 117, 138, 161, 185, 211, 237, 265, 293, 323, 353, 384, 415, 447, 479]
    
    # TRAINGLE
    elif(cmd == "1"):
        data = [0, 20, 41, 61, 82, 102, 123, 143, 164, 184, 205, 225, 246, 266, 286, 307, 327, 348, 368, 389, 409, 430, 450, 471, 491, 512, 532, 552, 573, 593, 614, 634, 655, 675, 696, 716, 737, 757, 777, 798, 818, 839, 859, 880, 900, 921, 941, 962, 982, 1003, 1023, 1003, 982, 962, 941, 921, 900, 880, 859, 839, 818, 798, 777, 757, 737, 716, 696, 675, 655, 634, 614, 593, 573, 552, 532, 512, 491, 471, 450, 430, 409, 389, 368, 348, 327, 307, 286, 266, 246, 225, 205, 184, 164, 143, 123, 102, 82, 61, 41, 20]
        
    # SQUARE
    elif(cmd == "2"):
        data = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    
    # DC
    elif(cmd == "3"):
        data = [1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023,1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023, 1023]
    else:
        data = [0]
    return data



    

if __name__ == "__main__":

    data = get_DAC_data("2")
    while 1:
        for i in data:
            DA0.value = bool(i & 0b00_0000_0001)
            DA1.value = bool(i & 0b00_0000_0010)
            DA2.value = bool(i & 0b00_0000_0100)
            DA3.value = bool(i & 0b00_0000_1000)
            DA4.value = bool(i & 0b00_0001_0000)
            DA5.value = bool(i & 0b00_0010_0000)
            DA6.value = bool(i & 0b00_0100_0000)
            DA7.value = bool(i & 0b00_1000_0000)
            DA8.value = bool(i & 0b01_0000_0000)
            DA9.value = bool(i & 0b10_0000_0000)
            t = 1/12e6
            time.sleep(t)



